#include <iostream>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int f[N];
ll mmin;
ll p;
ll q,y;
ll n;
ll x;
void dfs(ll u,ll v)
{
    if(v>=mmin) return;
    if(u==0)
    {
        mmin=v;
        return;
    }
    dfs((u+x)%n,v+p);
    dfs(((u-q)%n+n)%n,v+q);
}
int main()
{
    ll sum=0;
    
    cin>>n>>p>>x>>q>>y;
    for(int i=0;i<n;i++)
    {
        ll num=0;
        cin>>num;
        sum+=num;
    }
    mmin=n-sum%n;
    dfs(sum%n,0);
    cout<<mmin;
    return 0;
}
